<?php
    header("content-type:text/html; charset=utf8");
    $con = mysqli_connect("localhost", "root", "guodong", "study");
    mysqli_set_charset($con, "utf8");

    if ($con) {
        // switch ($_GET['action']) {
        // case 'add':
        $name = $_POST['name'];
        $age = $_POST['age'];
        $sex = $_POST['sex'];
        $class = $_POST['class'];
        
        $add = "INSERT INTO stu (`name`, age, sex, class) VALUES ('$name', '$age', '$sex', '$class')";
        $result = mysqli_query($con, $add);
                
        if ($result > 0) {
            echo "添加成功";
        } else {
            echo "添加失败";
        }
                
        // break;
        // }
    } else {
        echo '数据库连接失败';
    }
